//
//  HJRefreshHeader.m
//  KaiChat
//
//  Created by lx on 2023/10/17.
//

#import "HJRefreshHeader.h"
#import <FLAnimatedImage.h>

@interface HJRefreshHeader()

@property (nonatomic, weak) FLAnimatedImageView *microphoneImageView;

@end


@implementation HJRefreshHeader

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
  
        FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"refreshLoading.gif" withExtension:nil]]];
        FLAnimatedImageView *microphoneImageView = [[FLAnimatedImageView alloc] init];
        microphoneImageView.animatedImage = image;
        [self addSubview:microphoneImageView];
        _microphoneImageView = microphoneImageView;
    }
    return self;
}
 
- (void)placeSubviews
{
    [super placeSubviews];
    self.microphoneImageView.frame = CGRectMake((self.mj_w - 60) * 0.5, (self.mj_h - 24) * 0.5, 60, 24);
}

- (void)setState:(MJRefreshState)state
{
    MJRefreshCheckState
    if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) {
        self.microphoneImageView.hidden = NO;
        [self.microphoneImageView startAnimating];
    } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) {
        [self.microphoneImageView stopAnimating];
        self.microphoneImageView.hidden = YES;
    }
}

@end
